package com.briup.bms.web.controller;

import com.briup.bms.common.utils.Result;
import com.briup.bms.service.SWareHouseService;
import com.briup.bms.web.vm.WareHouseVO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: Paocha
 * @date: 2021-11-22-23:07
 */
@Api(tags = "仓库信息服务")
@RestController
@RequestMapping("WareHouse")
public class WareHouseController {

    @Autowired
    SWareHouseService wareHouseService;

    @ApiOperation(value = "按条件分页显示仓库信息")
    @GetMapping("/by/condition")
    public Result<PageInfo<WareHouseVO>> findByCondition(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "5") int pageSize,
            Integer id, String region,
            String manager) {

        return Result.success(wareHouseService.findByCondition(
                pageNum, pageSize, id,region,manager));
    }

    @GetMapping("/")
    public Result<PageInfo<WareHouseVO>> findByPageHelper(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "5") int pageSize){
        return Result.success(wareHouseService.findByPageHelper(pageNum,pageSize));
    }
    @PostMapping("/")
    public Result<String> insertEmployee(@RequestBody WareHouseVO wareHouseVO){
        wareHouseService.insert(wareHouseVO);
        return Result.success("添加成功");
    }
    @PutMapping("/update")
    public Result<String> updateEmployee(@RequestBody WareHouseVO wareHouseVO){
        wareHouseService.updateWareHouse(wareHouseVO);
        return Result.success("添加成功");
    }

    @DeleteMapping("/batchDelete")
    public Result<String> batchDelete(Integer[] ids){
        wareHouseService.batchDelete(ids);
        return Result.success("删除成功");
    }
}
